<?php

/**
 * Handle an Image upload for the background image.
 *
 * @since 3.0.0
 */
function handle_upload() {
    if (empty($_FILES))
        return;
    check_admin_referer('custom-background-upload', '_wpnonce-custom-background-upload');
    $overrides = array('test_form' => false);
    $file = wp_handle_upload($_FILES['import'], $overrides);
    if (isset($file['error']))
        wp_die($file['error']);
    $url = $file['url'];
    $type = $file['type'];
    $file = $file['file'];
    $filename = 'logo.png';

    rename($file, get_theme_root() . '/build/images/' . $filename);
}

handle_upload();

function abee_handleGA() {
    if (isset($_POST['ga_code'])) {
        add_option('abee_gacode', '', null, $autoload = 'yes');
        update_option('abee_gacode', $_POST['ga_code']);
    }
    return stripslashes( get_option('abee_gacode') );
}

$abee_gacode = abee_handleGA();
?>
<div class="wrap">
    <div id="icon-options-general" class="icon32"><br></div>
    <h2>Ustawienia Ogólne</h2>

    <div class="abee_adminwrap">
        <h3>Logo strony</h3>
        <table class="form-table">
            <tbody>
                <tr valign="top">
                    <th scope="row">Aktualne logo</th>
                    <td>
                        <label>Ciemne tło dodane dla białych obrazów</label><br/>
                        <div style="background-color: #777; border: solid 1px #000; display: inline-block">
                            <?php
                            if( is_file( get_theme_root().'/'. get_template() . '/images/' . 'logo.png')) :
                            ?>
                            <img src="<?= get_bloginfo('template_url') . '/images/' . 'logo.png' ?>"/>
                            <?php else : ?>
                            Brak
                            <?php endif;?>
                        </div>

                    </td>
                </tr>
                <tr valign="top">
                    <th scope="row"><?php _e('Upload Image'); ?></th>
                    <td>
                        <form enctype="multipart/form-data" id="upload-form" method="post" action="">
                            <label for="upload">Wybierz obrazek z Twojego komputera (maksymalny rozmiar 330x80px) :</label><br /><input type="file" id="upload" name="import" />
                            <input type="hidden" name="action" value="save" />
                            <?php wp_nonce_field('custom-background-upload', '_wpnonce-custom-background-upload') ?>
                            <?php submit_button(__('Upload'), 'button', 'submit', false); ?>
                        </form>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <div div="abee_adminwrap">
        <h3>Google Analytics</h3>
        <table class="form-table">
            <tbody>
                <tr valign="top">
                    <th scope="row">Wprowadź swój kod</th>
                    <td>
                        <form id="upload-form" method="post" action="">
                            <textarea style="height: 150px;width: 400px;" name="ga_code"><?php echo $abee_gacode ?></textarea><br/>
                            <?php submit_button(__('Ok'), 'button', 'submit', false); ?>
                        </form>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
